package com.book.single.single;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.util.Log;

public class BootCompleteReceiver extends BroadcastReceiver {

//    private static final String ACTION = "android.intent.action.BOOT_COMPLETED";


    @Override
    public void onReceive(Context context, Intent intent) {
        if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
//            Intent thisIntent = new Intent(context, MainActivity.class);
//            thisIntent.setAction("android.intent.action.MAIN");
//            thisIntent.addCategory("android.intent.category.LAUNCHER");
//            thisIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            context.startActivity(thisIntent);

            //第一种方式：根据包名
            PackageManager packageManager = context.getPackageManager();
            Intent mainIntent = packageManager.getLaunchIntentForPackage("com.book.single.single");
            mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mainIntent);
//            context.startService(mainIntent);
        }
    }
}
